home *** CD-ROM | disk | FTP | other *** search
- Message-ID: <30FBCAA1.34A7@novell.com>
- Date: Tue, 16 Jan 1996 15:56:17 +0000
- From: Greg Johnson <gregjo@novell.com>
- Organization: Novell, Inc.
- X-Mailer: Mozilla 2.0b3 (Win95; I)
- MIME-Version: 1.0
- Newsgroups: comp.lang.c++
- Subject: Overload of operator=
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- NNTP-Posting-Host: pcgjohnson2.orem.novell.com
- Path: news.provo.novell.com!
-
- I want to overload the assignment operator, for some debugging purposes.
- But after I overload the operator, somehow, I need to perform the
- default assignment. How do I do that if I don't know the exact size
- of the source or destination?
- How do I avoid recursion and perform the default behavior?
- For example:
-
- class BaseObj {
- public:
- long x;
- BaseObj& operator=(BaseObj&);
- BaseObj(void) : x(0) {};
- };
-
- BaseObj& BaseObj::operator=(BaseObj & ptr)
- {
- *this = ptr; // this will recursively call operator=
- return *this;
- }
-
- void foo()
- {
- BaseObj bo1;
- BaseObj bo2;
-
- bo1.x = 99;
- bo2 = bo1;
- }
-
- in operator=, the '*this = ptr' line causes a recursive call.
- How can I avoid the recursion and perform the correct assignment?
- I could do a memcpy, but I need to determine the size of the source
- and destination (either one may be base pointers to a more complex
- class.)
- Is there a way to determine the size of an object created with 'new'?
-